package com.woniuxy.prescription.controller;

import com.woniuxy.commons.entity.Medicine;
import com.woniuxy.commons.entity.Prescription;
import com.woniuxy.commons.service.IDoctorService;
import com.woniuxy.commons.service.MedicineService;
import com.woniuxy.commons.service.UserService;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.prescription.service.PrescriptionService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author Waves
 * @date 2022/6/8 10:46
 */

@RestController
@RequestMapping("/prescription")
public class PrescriptionController {

    @Resource
    private PrescriptionService prescriptionService;

    @Resource
    private UserService userService;

    @Resource
    private MedicineService MedicineService;

    @Resource
    private IDoctorService iDoctorService;

    @GetMapping("/{currentPage}/{pageSize}")
    @ApiOperation(value = "获取分页全部处方数据")
    public ResponseResult findAll(@ApiParam(name = "currentPage", value="当前页码",required=true)@PathVariable int currentPage,
                                  @ApiParam(name = "pageSize", value="页面大小",required=true)@PathVariable int pageSize){
        return prescriptionService.findAll(currentPage, pageSize);
    }

    @GetMapping("/{currentPage}/{pageSize}/{keyPath}")
    @ApiOperation(value = "获取分页不同状态处方数据")
    public ResponseResult findByStatus(@ApiParam(name = "currentPage", value="当前页码",required=true)@PathVariable int currentPage,
                                  @ApiParam(name = "pageSize", value="页面大小",required=true)@PathVariable int pageSize,
                                       @ApiParam(name = "keyPath", value="审核状态",required=true)@PathVariable int keyPath){
        return prescriptionService.findByStatus(currentPage, pageSize,keyPath);
    }

    @PutMapping("/batchDelete")
    @ApiOperation(value = "批量删除处方")
    public ResponseResult batchDelete(@ApiParam(name = "ids", value="处方id数组",required=true)@RequestBody int[] ids){
        return prescriptionService.batchDelete(ids);
    }
    
    @PostMapping("/add")
    @ApiOperation(value = "新增处方")
    public ResponseResult addOne(@ApiParam(name = "prescription", value="处方实体类",required=true)@RequestBody Prescription prescription){
        return prescriptionService.addOne(prescription);
    }
    
    @PutMapping("/update")
    @ApiOperation(value = "修改处方")
    public ResponseResult updateOne(@ApiParam(name = "prescription", value="处方实体类",required=true)@RequestBody Prescription prescription){
        return prescriptionService.updateOne(prescription);
    }
    
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除处方")
    public ResponseResult deleteOne(@ApiParam(name = "id", value="处方id",required=true)@PathVariable int id){
        return prescriptionService.deleteOne(id);
    }

    @PostMapping("/search")
    @ApiOperation(value = "查询处方")
    public ResponseResult findByContext(@ApiParam(name = "prescription", value="处方实体",required=true)@RequestBody Prescription prescription){
        return prescriptionService.findByContext(prescription);
    }

    @GetMapping("/findByRecord/{id}")
    @ApiOperation(value = "根据用户id查询用户")
    public ResponseResult findByRecord(@ApiParam(name = "用户id",value = "id") @PathVariable(value = "id") int id){
        return userService.findByRecord(id);
    }

    @PostMapping("/batchFind")
    @ApiOperation(value = "根据药品id获药品")
    public ResponseResult<List<Medicine>> findBatch(@RequestBody int[] ids){
        return MedicineService.findBatch(ids);
    }

    @GetMapping("/findMedicineIdsByPid/{id}")
    @ApiOperation(value = "根据处方id获药品数组id")
    public ResponseResult findMedicineIdsByPid(@ApiParam(name = "处方id",value = "id") @PathVariable int id){
        return prescriptionService.findMedicineIdsByPid(id);
    }

    @PostMapping("/findMedicine_Medicine")
    @ApiOperation(value = "获取处方用药详情")
    public ResponseResult findMedicine_Medicine(@ApiParam(name = "药品ids",value = "ids") @RequestBody int[] ids){
        return prescriptionService.findMedicine_Medicine(ids);
    }

    @GetMapping("findDoctorById/{id}")
    @ApiOperation(value = "根据医生id查询医生")
    public ResponseResult findDoctorById(@ApiParam(name = "医生id",value = "id") @PathVariable long id){
        return iDoctorService.findDoctorById(id);
    }

    @GetMapping("/medicine")
    public ResponseResult<List<Medicine>> findAll(){
        return MedicineService.findAll();
    }

    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据id查询处方")
    public ResponseResult findById(@ApiParam(name = "id", value="处方id",required=true)@PathVariable int id){
        return prescriptionService.findById(id);
    }
}
